package com.bailian.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bailian.common.annotation.Log;
import com.bailian.common.core.controller.BaseController;
import com.bailian.common.core.domain.AjaxResult;
import com.bailian.common.enums.BusinessType;
import com.bailian.system.domain.BlBanner;
import com.bailian.system.service.IBlBannerService;
import com.bailian.common.utils.poi.ExcelUtil;
import com.bailian.common.core.page.TableDataInfo;

/**
 * BannerController
 * 
 * @author ruoyi
 * @date 2025-08-04
 */
@RestController
@RequestMapping("/system/banner")
public class BlBannerController extends BaseController
{
    @Autowired
    private IBlBannerService blBannerService;

    /**
     * 查询Banner列表
     */
    @PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlBanner blBanner)
    {
        startPage();
        List<BlBanner> list = blBannerService.selectBlBannerList(blBanner);
        return getDataTable(list);
    }

    /**
     * 导出Banner列表
     */
    @PreAuthorize("@ss.hasPermi('system:banner:export')")
    @Log(title = "Banner", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlBanner blBanner)
    {
        List<BlBanner> list = blBannerService.selectBlBannerList(blBanner);
        ExcelUtil<BlBanner> util = new ExcelUtil<BlBanner>(BlBanner.class);
        util.exportExcel(response, list, "Banner数据");
    }

    /**
     * 获取Banner详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:banner:query')")
    @GetMapping(value = "/{bannerId}")
    public AjaxResult getInfo(@PathVariable("bannerId") Long bannerId)
    {
        return success(blBannerService.selectBlBannerByBannerId(bannerId));
    }

    /**
     * 获取所有Banner页面类型列表（去重）
     */
    @PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/pages")
    public AjaxResult getAllBannerPages()
    {
        List<String> pages = blBannerService.selectAllBannerPages();
        return success(pages);
    }

    /**
     * 根据页面类型获取Banner列表
     */
    @PreAuthorize("@ss.hasPermi('system:banner:list')")
    @GetMapping("/page/{bannerPage}")
    public AjaxResult getBannersByPage(@PathVariable("bannerPage") String bannerPage)
    {
        List<BlBanner> banners = blBannerService.selectBlBannerByBannerPage(bannerPage);
        return success(banners);
    }

//    /system/banner/bannerfile

    /**
     * 新增Banner
     */
    @PreAuthorize("@ss.hasPermi('system:banner:add')")
    @Log(title = "Banner", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlBanner blBanner)
    {
        return toAjax(blBannerService.insertBlBanner(blBanner));
    }

    /**
     * 修改Banner
     */
    @PreAuthorize("@ss.hasPermi('system:banner:edit')")
    @Log(title = "Banner", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlBanner blBanner)
    {
        return toAjax(blBannerService.updateBlBanner(blBanner));
    }

    /**
     * 删除Banner
     */
    @PreAuthorize("@ss.hasPermi('system:banner:remove')")
    @Log(title = "Banner", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bannerIds}")
    public AjaxResult remove(@PathVariable Long[] bannerIds)
    {
        return toAjax(blBannerService.deleteBlBannerByBannerIds(bannerIds));
    }
}
